import java.util.LinkedList;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;

public class ThreadDemo1 {
    public static void main(String[] args) {
        BlockingDeque<Integer> blockingQueue = new LinkedBlockingDeque<>();
        Thread customer = new Thread(() -> {
            while(true) {
                try {
                    int a = blockingQueue.take();
                    System.out.println("消费元素为：" + a);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        Thread producer = new Thread(() -> {
            int n = 0;
            while(true) {
                try {
                    System.out.println("生产元素为：" + n);
                    blockingQueue.put(n++);
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        customer.start();
        producer.start();
    }
}
